package cn.bdqn.mh.controller.api;


import cn.bdqn.mh.pojo.Ad;
import cn.bdqn.mh.pojo.Article;
import cn.bdqn.mh.pojo.House;
import cn.bdqn.mh.response.Result;
import cn.bdqn.mh.response.ResultCode;
import cn.bdqn.mh.service.HouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/house")
@Configuration(value = "website")
@Api(value = "房屋信息接口文档")
@Slf4j
public class HouseController {

    @Autowired
    private HouseService houseService;

    @GetMapping("/list1")
    @ApiOperation(value = "查询今日好房")
    public Object list1(){
        List<House> list=houseService.getListGoodHouse();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/list2")
    @ApiOperation(value = "查询优惠房源")
    public Object list2(){
        List<House> list=houseService.getListClicks();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/list3")
    @ApiOperation(value = "查询地铁沿线")
    public Object list3(){
        List<House> list=houseService.getListIsMetroLine();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/list4")
    @ApiOperation(value = "查询低价月付")
    public Object list4(){
        List<House> list=houseService.getListByMoney();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/list5")
    @ApiOperation(value = "查询温馨一居")
    public Object list5(){
        List<House> list=houseService.getListByHouseType();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/search")
    @ApiOperation(value = "搜索房源信息")
    public Object search(@ApiParam(name = "title",value = "要查找的地区、小区、地铁名称",required = false)
                         @RequestParam(value = "title",required = false) String title){
        List<House> list=houseService.search(title);
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }

    @GetMapping("/salemoney")
    @ApiOperation(value = "查询特色房源")
    public Object saleMoney(){
        List<House> list=houseService.getSaleMoney();
        Result result=null;
        if(list==null || list.size()==0){
            result = new Result(ResultCode.NO_DATAFOUND);
        }else {
            result = new Result(ResultCode.SUCCESS,list);
        }
        return result;
    }



}
